package com.zmn.uac.client;

import com.zmn.base.common.data.common.dro.company.CompanyDRO;
import com.zmn.base.common.data.dubbo.interfaces.company.CompanyListRemoteService;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.mcc.common.dto.staff.StaffDRO;
import com.zmn.mcc.dubbo.interfaces.staff.StaffListRemoteService;
import com.zmn.uac.UacException;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * @title: 员工相关Dubbo接口
 * @author:Rananquan
 * @Date:2022/6/9 16:11
 */
@Slf4j
@Component
public class StaffListClient {

    @DubboReference(version = com.zmn.mcc.dubbo.dto.DubboConsts.INTERFACE_VERSION, check = false)
    StaffListRemoteService staffListRemoteService;

    @DubboReference(version = com.zmn.mcc.dubbo.dto.DubboConsts.INTERFACE_VERSION, check = false)
    CompanyListRemoteService companyListRemoteService;


    /**
     * 查询员工相关信息
     * @param staffId 员工ID
     * @return
     */
    public StaffDRO getStaff(Integer staffId){
        log.info("根据userId获取员工信息入参：{}",staffId);
        ResponseDTO<StaffDRO> staffResponse = staffListRemoteService.getStaff(staffId);
        if(!staffResponse.isSuccess()){
            log.error("根据userId获取员工信息请求失败，失败原因：{}",staffResponse.getMessage());
            throw new UacException(staffResponse.getMessage());
        }

        StaffDRO staff = staffResponse.getData();
        log.info("根据userId获取员工返回response：[{}]",staff);

        return staff;
    }

    public CompanyDRO getCompany( Integer companyId) {
        log.info("根据companyId获取员工信息入参：{}",companyId);
        ResponseDTO<CompanyDRO> staffResponse = companyListRemoteService.getCompanyDROById(companyId);
        if(!staffResponse.isSuccess()){
            log.error("根据companyId获取员工信息请求失败，失败原因：{}",staffResponse.getMessage());
            throw new UacException(staffResponse.getMessage());
        }
        CompanyDRO companyDRO = staffResponse.getData();
        log.info("根据companyId获取员工返回response：[{}]",companyDRO);
        return companyDRO;
    }
}
